home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / vol15n11.zip / TBWIZ.ZIP / TBLOAD.FRM < prev    next >
Text File  |  1996-02-24  |  9KB  |  295 lines

  1. VERSION 4.00
  2. Begin VB.Form tbLoadForm 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Load Toolbar"
  5.    ClientHeight    =   1590
  6.    ClientLeft      =   4680
  7.    ClientTop       =   6795
  8.    ClientWidth     =   4515
  9.    ControlBox      =   0   'False
  10.    Height          =   1995
  11.    Left            =   4620
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   1590
  16.    ScaleWidth      =   4515
  17.    ShowInTaskbar   =   0   'False
  18.    Top             =   6450
  19.    Width           =   4635
  20.    Begin VB.CommandButton Command2 
  21.       Caption         =   "Cancel"
  22.       Height          =   325
  23.       Left            =   3480
  24.       TabIndex        =   2
  25.       Top             =   720
  26.       Width           =   975
  27.    End
  28.    Begin VB.CommandButton Command1 
  29.       Caption         =   "&Open"
  30.       Height          =   325
  31.       Left            =   3480
  32.       TabIndex        =   4
  33.       Top             =   240
  34.       Width           =   975
  35.    End
  36.    Begin VB.Frame Frame1 
  37.       Caption         =   "Name Controls:"
  38.       Height          =   1335
  39.       Left            =   120
  40.       TabIndex        =   0
  41.       Top             =   120
  42.       Width           =   3135
  43.       Begin VB.TextBox Text1 
  44.          Height          =   285
  45.          Index           =   1
  46.          Left            =   1200
  47.          TabIndex        =   6
  48.          Text            =   "tbwizIL1"
  49.          Top             =   840
  50.          Width           =   1695
  51.       End
  52.       Begin VB.TextBox Text1 
  53.          Height          =   285
  54.          Index           =   0
  55.          Left            =   1200
  56.          TabIndex        =   5
  57.          Text            =   "tbwizTB1"
  58.          Top             =   360
  59.          Width           =   1695
  60.       End
  61.       Begin VB.Label Label1 
  62.          AutoSize        =   -1  'True
  63.          Caption         =   "ImageList:"
  64.          Height          =   195
  65.          Index           =   1
  66.          Left            =   240
  67.          TabIndex        =   3
  68.          Top             =   860
  69.          Width           =   720
  70.       End
  71.       Begin VB.Label Label1 
  72.          AutoSize        =   -1  'True
  73.          Caption         =   "Toolbar:"
  74.          Height          =   195
  75.          Index           =   0
  76.          Left            =   360
  77.          TabIndex        =   1
  78.          Top             =   390
  79.          Width           =   585
  80.       End
  81.    End
  82.    Begin MSComDlg.CommonDialog CommonDialog1 
  83.       Left            =   3720
  84.       Top             =   1080
  85.       _Version        =   65536
  86.       _ExtentX        =   847
  87.       _ExtentY        =   847
  88.       _StockProps     =   0
  89.       CancelError     =   -1  'True
  90.       DefaultExt      =   "*.tbr"
  91.       DialogTitle     =   "Load Toolbar"
  92.       Filter          =   "*.tbr | Toolbars"
  93.    End
  94. End
  95. Attribute VB_Name = "tbLoadForm"
  96. Attribute VB_Creatable = False
  97. Attribute VB_Exposed = False
  98. Option Explicit
  99.  
  100.  
  101.  
  102.  
  103. Function LoadTB() As Integer
  104. '___init vars
  105. Dim CurrFormName$, CurrFormFiles$(1)
  106. Dim i%, ii%
  107. Dim success As Boolean
  108. Dim MyForm As Object
  109. Dim qm$
  110. qm = Chr$(34)
  111. Const frx = ".frx"
  112. Dim guid$, major$, minor$, ocx$
  113. guid$ = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}"
  114. major$ = "1.0"
  115. minor$ = "0"
  116. ocx$ = "COMCTL32.OCX"
  117.  
  118.  
  119. '___get project info
  120. With gobjIDEAppInst.ActiveProject
  121.     '___add reference to toolbar & imagelist controls
  122.     On Error Resume Next
  123.     .AddToolboxTypelib guid$, major$, minor$, ocx$
  124.     On Error GoTo 0
  125.    
  126.     '___get form file names
  127.     CurrFormName$ = .ActiveForm.Properties.Item("Name")
  128.     With .Components
  129.         For i% = 0 To .Count - 1
  130.             If .Item(i%).Name = CurrFormName$ Then
  131.                 CurrFormFiles$(0) = .Item(i%).FileNames(0)
  132.                 CurrFormFiles$(1) = .Item(i%).FileNames(1)
  133.                 Set MyForm = .Item(i%)
  134.             End If
  135.         Next
  136.     End With
  137. End With
  138. On Error GoTo 0
  139.  
  140. '___make sure this file has been saved
  141. If Exists%(CurrFormFiles$(0)) = 0 Then
  142.     Alert "Please save " & CurrFormName$ & "before attempting to load a toolbar onto it."
  143.     LoadTB = 0
  144.     Exit Function
  145. End If
  146.  
  147. '___get TBR file name from user
  148. On Error Resume Next
  149. CommonDialog1.FileName = "*.tbr"
  150. CommonDialog1.ShowOpen
  151. If Err = cdlCancel Then LoadTB = 0: Exit Function
  152. On Error GoTo 0
  153. gfnameTBFile = CommonDialog1.FileName
  154.  
  155. '___init some more vars
  156. Screen.MousePointer = HOURGLASS
  157. Const icTest = "ComctlLib.ImageList"
  158. Const tbTest = "ComctlLib.Toolbar"
  159. Dim linetest$
  160. Dim Target$
  161. Dim Source$
  162. Dim tmpfile$
  163. Dim frxTarg$
  164. Dim BeenThere As Boolean
  165. Dim ilOrg$, ilNew$
  166. Dim tbOrg$, tbNew$
  167. ilNew$ = Text1(1)
  168. tbNew$ = Text1(0)
  169.  
  170. '___build source, target and temp file names
  171. frxTarg$ = ExtractFilePath$(gfnameTBFile) + ExtractFileRoot(gfnameTBFile)
  172. Source$ = gfnameTBFile
  173. If Exists%(Source$) = 0 Then Alert "Can't find that toolbar file!": Exit Function
  174. Target$ = CurrFormFiles$(0)
  175. tmpfile$ = ExtractFilePath$(Target$) + "tmpfrm.frm"
  176.  
  177. '___remove target form from project & rename it
  178. ii% = gobjIDEAppInst.ActiveProject.RemoveComponent(MyForm, True)
  179. Name Target$ As tmpfile$
  180. Open Target$ For Output As #1
  181. Open tmpfile$ For Input As #3
  182.  
  183. '___run through tbr file to determine original names of toolbar & imagelist controls
  184. Open Source$ For Input As #2
  185. Do While Not EOF(2)
  186.      Line Input #2, linetest$
  187.      If InStr(linetest$, icTest$) > 0 Then
  188.         linetest$ = Trim$(linetest$)
  189.         For ii% = Len(linetest$) To 1 Step -1
  190.             If Mid$(linetest$, ii%, 1) = Chr$(32) Then
  191.                 ilOrg$ = Mid$(linetest$, ii% + 1)
  192.                 Exit For
  193.             End If
  194.         Next
  195.     End If
  196.     If InStr(linetest$, tbTest$) > 0 Then
  197.         linetest$ = Trim$(linetest$)
  198.         For ii% = Len(linetest$) To 1 Step -1
  199.             If Mid$(linetest$, ii%, 1) = Chr$(32) Then
  200.                 tbOrg$ = Mid$(linetest$, ii% + 1)
  201.                 Exit For
  202.             End If
  203.         Next
  204.     End If
  205.     If (Len(tbOrg$) * Len(ilOrg$)) <> 0 Then Exit Do
  206. Loop
  207. Close #2
  208.  
  209. '__*** showtime ***
  210. '___copy current form file line by line into target file
  211. Open Source$ For Input As #2
  212. Do While Not EOF(3)
  213.    Line Input #3, linetest$
  214.    Print #1, linetest$
  215.    '___insert control defs from toolbar file into target after form WIDTH definition
  216.    If (Left$(Trim$(linetest$), 5)) = "Width" And (BeenThere = False) Then
  217.          BeenThere = True
  218.          Line Input #2, linetest$
  219.          Do Until Trim$(linetest$) = "TB_EVENTS"
  220.            If InStr(linetest$, frx) > 0 Then    '___fix frx file reference
  221.                 i% = InStr(linetest$, qm)
  222.                 linetest$ = Left$(linetest$, i%) + frxTarg$ + Mid$(linetest$, (InStr(linetest$, frx)))
  223.            End If
  224.            '___substitute new names for tb & il controls
  225.            i% = InStr(linetest$, ilOrg$)
  226.            If i% > 0 Then
  227.               linetest$ = Left$(linetest$, i% - 1) + ilNew$ + Mid$(linetest$, i% + Len(ilOrg$))
  228.            End If
  229.            i% = InStr(linetest$, tbOrg$)
  230.            If i% > 0 Then
  231.               linetest$ = Left$(linetest$, i% - 1) + tbNew$ + Mid$(linetest$, i% + Len(tbOrg$))
  232.            End If
  233.            Print #1, linetest$
  234.            Line Input #2, linetest$
  235.          Loop
  236.    End If
  237. '___copy remainder of form source file
  238. Loop
  239.         
  240. '___now add tbr event handling code to end of target file
  241. Do Until EOF(2)
  242.            Line Input #2, linetest$
  243.             '___substitute specified names for il & tb
  244.             i% = InStr(linetest$, ilOrg$)
  245.            If i% > 0 Then
  246.               linetest$ = Left$(linetest$, i% - 1) + ilNew$ + Mid$(linetest$, i% + Len(ilOrg$))
  247.            End If
  248.            i% = InStr(linetest$, tbOrg$)
  249.            If i% > 0 Then
  250.               linetest$ = Left$(linetest$, i% - 1) + tbNew$ + Mid$(linetest$, i% + Len(tbOrg$))
  251.            End If
  252.            Print #1, linetest$
  253. Loop
  254. '___clean up
  255. Close #1
  256. Close #2
  257. Close #3
  258. Kill tmpfile$
  259. '___bring form file  back into project
  260. tmpfile$ = gobjIDEAppInst.ActiveProject.AddFile(Target$)
  261. Set MyForm = Nothing
  262. '___wait a bit
  263. i% = DoEvents%()
  264. i%